import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86183
 * Date: 2022-10-11
 * Time: 9:46
 */
public class TestHeap {
    public int[] elem;
    public int usedSize;
    public static final int DEFAULT_SIZE = 10;
    public TestHeap(){
        elem = new int[DEFAULT_SIZE];
    }
    public void initElem(int[] array){
        for (int i = 0; i < array.length; i++) {
            elem[i] = array[i];
            usedSize++;
        }
    }
   public void createHeap(){
       for (int parent = (usedSize-1-1)/2; parent >= 0 ; parent--) {
           shiftDown(parent,usedSize);
       }
   }
   public void offer(int val){
        if(isFull()){
            elem = Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[usedSize] = val;
        usedSize++;
        shiftUp(usedSize-1);
   }
   private void shiftUp(int child){

   }
   public boolean isFull(){
        return usedSize == elem.length;
   }
   private void shiftDown(int parent,int len){
        int child = 2*parent+1;
        while (child < len){
            if(child+1 < len && elem[child]<elem[child+1]){
                child++;
            }
            if(elem[child] > elem[parent]){
                int tmp = elem[child];
                elem[child] = elem[parent];
                elem[parent] = tmp;
                parent = child;
                child = 2*parent +1;
            }else{
                break;
            }
        }
   }

}
